package com.example.javapoint.servlet;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

public class FirstServlet implements Servlet {
    ServletConfig config = null;
    @Override
    public void init(ServletConfig servletConfig) throws ServletException { // 初始化
        config = servletConfig;
    }

    @Override
    public ServletConfig getServletConfig() { // ServletConfig
        return config;
    }

    /**
     * 提供服务
     *
     * @param servletRequest 请求
     * @param servletResponse 响应
     * @throws ServletException ServletException
     * @throws IOException IOException
     */
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        servletResponse.setContentType("text/html");
        PrintWriter out = servletResponse.getWriter();
        out.println("<html><body>");
        out.print("<b>hello simple servlet</b>");
        out.print("</body></html>");
    }

    @Override
    public String getServletInfo() {
        return "copyright 2025-1010";
    }

    @Override
    public void destroy() {
        System.out.println("servlet is destroyed");
    }
}
